const app = getApp();
Page({
    data: {
        orderId:'',
        cids:[],
        CartList:[],
        address:{},
        orderPrice:'',
        StatusBar: app.globalData.StatusBar,
        CustomBar: app.globalData.CustomBar,
        TabbarBot: app.globalData.tabbar_bottom,
    },
    onLoad: function (options) {
      let _this = this
      let list = new Array()
      console.log(JSON.parse(options.cids))
      _this.setData({
        cids: JSON.parse(options.cids)
      })
      _this.CartList()
      _this.addressInfo()
    },
    CartList:function(){
      let _this = this
      wx.request({
        method:'GET',
        url: 'http://localhost:8989/cart/check/' + _this.data.cids,
        success:(res) => {
          console.log(res)
          let orderPrice = 0
          for(let i = 0; i < res.data.data.shopVoList.length; i ++)
            orderPrice += res.data.data.shopVoList[i].allPrice
          _this.setData({
            CartList: res.data.data.shopVoList,
            orderPrice: orderPrice,
            orderId: res.data.data.orderid
          })
          console.log(_this.data.orderId)
          console.log(_this.data.CartList)
          console.log(_this.data.orderPrice)
        }
      })
    },
    addressInfo:function(){
      let _this = this
      wx.getStorage({
        key:'user',
        success:(res) =>{
          wx.request({
            method:'GET',
            url: 'http://localhost:8989/address/DeAddress/' + res.data.uid,
            success:(result) => {
              _this.setData({
                address: result.data.data
              })
            }
          })
        }
      })
    },

    getOrder:function(){
      let _this = this
      // wx.request({
      //   method:"GET",
      //   url: 'http://localhost:8989/alipay/pay',
      //   data:{
      //     traceNo: _this.data.orderId,
      //     totalAmount: _this.data.orderPrice,
      //     subject: "为用户支付",

      //   },
      //   success:(res=>{
      //     console.log(res)
      //     console.log("支付")
      //     wx.navigateTo({
      //       url: '/pages/order/index/index?OrderId=' + 123
      //     });
      //   })
      // })
      wx.getStorage({
        key: 'user',
        success: function (res) {
          wx.request({
            url: 'http://localhost:8989/order/saveOrder/' + res.data.uid,
            data:{
              orderid: _this.data.orderId
            },
            success:(res=>{
              console.log("支付成功")
            })
          })
        }
      });
            wx.navigateTo({
            url: '/pages/order/index/index?OrderId=' + 123
          });
    }
});
